home *** CD-ROM | disk | FTP | other *** search
/ Chip 2000 November / Chip Kasım 2000.iso / prog / share / 11 / setup.exe / %MAINDIR% / DEMOS / CIHTTP / HTTPEXP / callback.cls < prev    next >
Encoding:
Visual Basic class definition  |  2000-09-07  |  8.3 KB  |  252 lines

  1. VERSION 1.0 CLASS
  2. BEGIN
  3.   MultiUse = -1  'True
  4. END
  5. Attribute VB_Name = "HTTPCallback"
  6. Attribute VB_GlobalNameSpace = False
  7. Attribute VB_Creatable = False
  8. Attribute VB_PredeclaredId = False
  9. Attribute VB_Exposed = False
  10. Option Explicit
  11.  
  12. '----------------------------------------------------
  13. '<Purpose> callback function to show the HTTPServer
  14. ' anchors in the TreeView
  15. '----------------------------------------------------
  16. Public Function ShowAnchors(ThisSession As Form, ThisExplorer As Form, ServerNode As Node)
  17.     Dim i               As Integer
  18.     Dim ListCount       As Integer
  19.     Dim TypeAnchor      As Integer
  20.     Dim TheseItems      As ListItems
  21.     Dim WorkingItem     As ListItem
  22.     Dim TheseNodes      As Nodes
  23.     Dim WorkingNode     As Node
  24.     Dim FullPathName    As String
  25.     Dim ListItem        As String
  26.     Dim NodeKey         As String
  27.     Dim ServerKey       As String
  28.     Dim SiteName        As String
  29.     'Dim Temp            As String
  30.     Dim WorkingDir      As String
  31.  
  32.     ServerKey = ServerNode.Key
  33.     
  34.     '---- cache explorer objects
  35.     Set TheseNodes = ThisExplorer.Tree.Nodes
  36.     Set TheseItems = ThisExplorer.List.ListItems
  37.     
  38.     WorkingDir = ThisSession.WorkingDir
  39.     SiteName = ThisSession.WWWSiteName
  40.  
  41.     '---- add all anchors and create extra data for each
  42.     With ThisSession
  43.         ListCount = .lstAnchors.ListCount - 1
  44.         For i = 0 To ListCount
  45.             ListItem = .lstAnchors.List(i)
  46.             TypeAnchor = AnchorType(ListItem)
  47.             If (TypeAnchor <> refFTPServer) Then
  48.                         
  49.                 '---- get the full path to a URL
  50.                 FullPathName = PrepareURL(ListItem, ServerNode)
  51.                 
  52.                 'NodeKey = ServerKey & "." & ListItem
  53.                 NodeKey = ServerKey & "." & FullPathName
  54.                 If (ListItem = "") Then GoTo NextItem   '---- seen it happen
  55.                 If (Not (TypeAnchor = refWebPage)) Then '---- pages are only displayed in the list
  56.                     If (Not IsKeyed(TheseNodes, NodeKey)) Then
  57.                         
  58.                         On Error GoTo DuplicateItem
  59.                         '---- add extra data
  60.                         Dim ThisAttachment As New Attachment
  61.                         ThisAttachment.NodeType = nodHTTPFolder
  62.                         ThisAttachment.DrivePath = FullPathName
  63.                         Set ThisAttachment.Session = ThisSession
  64.                         Call ThisExplorer.Attachments.Add(ThisAttachment, NodeKey)
  65.                         Set ThisAttachment = Nothing
  66.                         On Error GoTo 0
  67.                         
  68.                         Set WorkingNode = TheseNodes.Add(ServerNode, tvwChild, NodeKey, ListItem, imgHTTPLink, imgHTTPLinkOpen)
  69.                         
  70.                         '---- add searching placeholder
  71.                         Call TheseNodes.Add(WorkingNode, tvwChild, WorkingNode.Key & nodPlaceHolder, nodPlaceHolder, imgPlaceHolder)
  72.                     End If
  73.                 End If
  74.                 
  75.                 On Error GoTo DuplicateItem
  76.                 
  77.                 '---- add anchor to ListView; pad with invisible char for sorting purposes
  78.                 If (TypeAnchor = refWebPage) Then
  79.                     '<Launch Web Page>
  80.                     '---- special concatenator so parent key can be easily parsed
  81.                     Set WorkingItem = TheseItems.Add(, ServerKey & "~" & FullPathName, ListItem, imgHTTPFile, imgHTTPFile)
  82.                     WorkingItem.SubItems(2) = "Web Page"
  83.                     '<Launch Web Page>
  84.                 Else
  85.                     Set WorkingItem = TheseItems.Add(, NodeKey, Chr(160) & ListItem, imgHTTPLink, imgHTTPLink)
  86.                     WorkingItem.SubItems(2) = "Web Directory Link"
  87.                 End If
  88.                 
  89.                 On Error GoTo 0
  90.             End If
  91. NextItem:
  92.         Next
  93.     End With
  94.     
  95. Cleanup:
  96.     Set TheseItems = Nothing
  97.     Set TheseNodes = Nothing
  98.     Set WorkingNode = Nothing
  99.     Set WorkingItem = Nothing
  100.     Exit Function
  101.     
  102. DuplicateItem:
  103.     Resume NextItem
  104.     
  105. End Function
  106.  
  107.  
  108. '---------------------------------------------------------------
  109. '<Purpose> checks an anchor to see if does not refer to an
  110. ' FTP anchor
  111. '---------------------------------------------------------------
  112. Private Function AnchorType(ThisAnchor As String) As Integer
  113.     Dim CharPos As Integer
  114.  
  115.     '---- check to see if it has a page extension
  116.     CharPos = InStr(UCase(ThisAnchor), ".HTM")
  117.     If (CharPos > 0) Then
  118.         AnchorType = refWebPage
  119.         Exit Function
  120.     End If
  121.     
  122.     '---- ftp server reference
  123.     CharPos = InStr(UCase(ThisAnchor), "FTP://")
  124.     If (CharPos > 0) Then
  125.         AnchorType = refFTPServer
  126.         Exit Function
  127.     End If
  128.     
  129.     '---- http server reference
  130.     CharPos = InStr(UCase(ThisAnchor), "HTTP://")
  131.     If (CharPos > 0) Then
  132.         AnchorType = refHTTPServer
  133.         Exit Function
  134.     End If
  135.     
  136.     If (left(ThisAnchor, 1) = "/") Then
  137.         AnchorType = refFullPath
  138.         Exit Function
  139.     End If
  140.         
  141.     If (left(ThisAnchor, 3) = "../") Then
  142.         AnchorType = refDownPath
  143.         Exit Function
  144.     End If
  145.         
  146.     If (left(ThisAnchor, 1) <> "/") Then
  147.         AnchorType = refUpPath
  148.         Exit Function
  149.     End If
  150.     
  151.     AnchorType = refUnkown
  152.     
  153. End Function
  154.  
  155. '---------------------------------------------------------------
  156. '<Purpose> returns the last portion of an HTTP anchor;
  157. ' also returns if the item is a directory or page anchor
  158. '---------------------------------------------------------------
  159. Private Function ParseAnchor(ThisItem As String, IsPage As Boolean) As String
  160.     Dim CharPos As Integer
  161.     Dim Temp    As String
  162.     
  163.     Temp = ThisItem
  164.     Do
  165.         CharPos = InStr(Temp, "/")
  166.         If (CharPos = 0) Then Exit Do
  167.         If (CharPos = Len(Temp)) Then
  168.             Temp = left(Temp, Len(Temp) - 1)
  169.             Exit Do
  170.         End If
  171.         Temp = Mid(Temp, CharPos + 1)
  172.     Loop
  173.     
  174.     '---- check to see if it has a page extension
  175.     IsPage = (InStr(UCase(Temp), ".HTM") > 0)
  176.     
  177.     ParseAnchor = Temp
  178.     
  179. End Function
  180.  
  181. '----------------------------------------------------
  182. '<Purpose> prepares a full URL given an item from
  183. ' the 'anchors' list and a node
  184. '----------------------------------------------------
  185. Private Function PrepareURL(AnchorItem As String, ServerNode As Node) As String
  186.     Dim ThisAttachment  As New Attachment
  187.     Dim i               As Integer
  188.     Dim CharPos         As Integer
  189.     Dim ThisNode        As Node
  190.     Dim ParentURL       As String
  191.     Dim Temp            As String
  192.     
  193.     Temp = AnchorItem
  194.     
  195.     '---- items beginning with slashes should be absolute URLs
  196.     If (left(Temp, 1) = "/") Then
  197.         PrepareURL = Temp
  198.         GoTo Cleanup
  199.     End If
  200.     
  201.     '---- items beginning with http are absolute URLs
  202.     If (left(LCase(Temp), 7) = "http://") Then
  203.         PrepareURL = Temp
  204.         GoTo Cleanup
  205.     End If
  206.     
  207.     '---- relative reference
  208.     If (left(Temp, 3) = "../") Then
  209.     
  210.         Set ThisNode = ServerNode.Parent
  211.         Set ThisAttachment = Explorer.Attachments.Item(ThisNode.Key)
  212.         ParentURL = ThisAttachment.DrivePath
  213.         
  214.         Do
  215.             Temp = Mid(Temp, 4)
  216.             
  217.             '---- remove a directory from the parent URL
  218.             For i = Len(ParentURL) - 1 To 1 Step -1
  219.                 If (Mid(ParentURL, i, 1) = "/") Then
  220.                     ParentURL = left(ParentURL, i + 1)
  221.                     Exit For
  222.                 End If
  223.             Next
  224.             
  225.             '---- loop for all these types of references
  226.             CharPos = InStr(Temp, "../")
  227.             If (CharPos = 0) Then
  228.                 Temp = ParentURL & Temp
  229.                 Exit Do
  230.             End If
  231.         Loop
  232.         
  233.         PrepareURL = Temp
  234.         GoTo Cleanup
  235.     End If
  236.     
  237.     '---- else relative reference not begginning with slash
  238.     Set ThisNode = ServerNode.Parent
  239.     Set ThisAttachment = Explorer.Attachments.Item(ThisNode.Key)
  240.     ParentURL = ThisAttachment.DrivePath
  241.     If (ParentURL = "") Then
  242.         PrepareURL = "/" & Temp
  243.         GoTo Cleanup
  244.     End If
  245.     
  246.  
  247. Cleanup:
  248.     Set ThisNode = Nothing
  249.     Set ThisAttachment = Nothing
  250.  
  251. End Function
  252.